import React from 'react'
// ===================================================================== Temp
import TableModal from '#cpt/temp/TableModal'
import Cols from '#private/cols'
// ===================================================================== Declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const $cache = $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag:{},
		selectedKeys: [],
		forms : [
			{ label: '报告单模板',		name: 'report_id',		type: 'select' },
			{ label: '自然项目',			name: 'parent_kind_id',	type: 'select' },
			{ label: '项目',			name: 'kind_id',		type: 'select' },
			{ label: '是否查看往期',		name: 'show_past',		type: 'checkbox' },
		],
		formData : [
			{ label: '合并规则',		name: 'merge_group_id',		type: 'select-table', cols:Cols['merge_select'], half:true, required:true, onValue:({ rows })=>{
				console.log(rows)
			} },
		]
	}
	
	model = {}
	
	// 获取下拉数据
	getSelect = () => {
		const { forms, formData } = this.state
		$fn.setModalRows(forms, ['report_id', 'parent_kind_id', 'kind_id'], ()=>{
			$cache.then( async f => {
				// 报告单模板
				await $fn.setRowc(forms, 'report_id',  async () => await f.getCache({ api:'report_template' } ))
				// 自然项目
				await $fn.setRowc(forms, 'parent_kind_id',  async () => await f.getCache({ api:'nature_project' } ))
				// 项目
				await $fn.setRowc(forms, 'kind_id',  async () => await f.getCache({ api:'project_select' } ))
				//
				this.setState({ forms })
			})
		})
		$fn.setModalRows(formData, ['merge_group_id'], ()=>{
			$cache.then( async f => {
				// 合并规则
				await $fn.setRowc(formData, 'merge_group_id',  async () => await f.getCache({ api:'merge_select' } ))
				//
				this.setState({  formData })
			})
		})
	}
	
	open = (title,{rows, query}) => {
		this.modal.open({ formRef: this.formRef })
		// 搜索参数
		const { spec_code } = rows || {}
		this.query = { spec_code }
		// 获取下拉数据
		this.getSelect()
		//
		this.setState({ title })
		//
		this.fetch()
	}
	// paging
	fetch = () => $fn.fetch.call(this, 'ts-report-card/mergespec', { param: { limit: '100' } })
	
	// 表单
	cols = [
		{ title: '标本条码', 	dataIndex: 'spec_code', 				...$fn.table.spec_code },
		{ title: '自然项目', 	dataIndex: 'parent_kind_name', 			width:250 },
		{ title: '实验号', 		dataIndex: 'experiment_num', 			...$fn.table.exp_num },
		{ title: '项目名称', 	dataIndex: 'kind_name', 				width:250 },
		{ title: '报告单模板', 	dataIndex: 'report_name', 				width:150 },
		{ title: '姓名', 		dataIndex: 'patient_name', 				...$fn.table.name },
		{ title: '结果', 		dataIndex: 'result', 					...$fn.table.num },
		{ title: '结果类型', 	dataIndex: 'result_type_name', 			width:80 },
		{ title: '接收时间', 	dataIndex: 'receive_time', 				...$fn.table.time },
		{ title: '状态', 		dataIndex: 'status_name', 				width:80 },
	]
	
	render(){
		return TableModal.call(this,{ 
			title:'批准', width:'99%', height:'70%',  table:{ width:1200 }, api:'merge-report/add', 
			submit:{
				labelWidth:'s5',
				getSubmit: () => ( { ts_uuids: this.state.selectedKeys } )
			},
		})
	}
}

export default Index